package com.charlie.meetingmanagement.interceptors;

import com.charlie.meetingmanagement.utils.JwtUtil;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import java.util.Map;

@Component
public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//        令牌验证
        String token = request.getHeader("Authorization");
        System.out.println("intercept......");
//        验证token
        try {
            Map<String,Object> claims = JwtUtil.parseToken(token);
            System.out.println("该访问未被拦截");
            return true;
        }catch (Exception e){
            response.setStatus(401);
            System.out.println("该访问被拦截");
            return true;
//            return false;
        }
//        return true;
    }
}
